<template>
  <div class="fx-table-item">
    <slot name="default" :prop="prop"></slot>
  </div>
</template>

<script lang="ts">
import { defineComponent, inject, onMounted, PropType } from 'vue'
import { Emitter } from 'mitt'

interface TableItemProps {
  prop: string;
  label: string;
}

export default defineComponent({
  name: 'fxTableItem',
  props: {
    prop: {
      type: String as PropType<string>,
      required: true
    },
    label: {
      type: String as PropType<string>,
      default: ''
    }
  },
  setup (props: TableItemProps) {
    const tableMittEmit = inject<Emitter['emit'] | undefined>('tableMittEmit', undefined)

    onMounted(() => {
      tableMittEmit && tableMittEmit('handleTableHeader', { label: props.label, prop: props.prop })
    })

    return {}
  }
})
</script>
